#pragma once

#include <list>
#include <mutex>

class QWebSocket;
class QString;
class Session;

class Client
{
public:
    Client(QWebSocket *websocket, const QString &browser)
        : websocket(websocket), browser(browser)
    { }
public:
    QWebSocket *websocket;
    QString browser;
};

class ClientManager
{
public:
    ClientManager();
    ~ClientManager();
public:
    // pop first active client and push it to the back
    Client *popFirstActiveClient();
public:
    // slots:
    void onNewConnection(QWebSocket *client);
    void onUnknownClientTextMessageRecieved(QWebSocket *client, QString message);

    void onClientTextMessageRecieved(QWebSocket *client, QString message);
    void onClientDisconnected();

public:
    // public static methods:
    static ClientManager *instance();
private:
    // internal methods:
    void registerNewClient(QWebSocket * client, const QString& browser);

    void push_back(Client *client);
    void push_front(Client *client);
    Client * pop_front();
    size_t size();

    // search though queue and return whether active client exists.
    bool hasActiveClients();

    // get first active client without poping it.
    Client *firstActiveClient();
private:
    // internal variables
    std::list<Client *> clientsQueue;
private:
    // internal static variables
    static ClientManager *_instance;
};